/*
 * events.cc
 *
 *  Copyright (C) 2012  Pierre Beaucamp
 *
 *	This file is part of the Program CRAFTING
 *
 *  CRAFTING is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  CRAFTING is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with CRAFTING.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "events.h"

events::events() {
}

events::~events() {
}

void events::onEvent(SDL_Event* event) {
	switch(event->type) {

		case SDL_ACTIVEEVENT: {
			switch(event->active.state) {

				case SDL_APPMOUSEFOCUS: {
					if (event->active.gain) onMouseFocus();
					else onMouseBlur();
					break;
				}

				case SDL_APPINPUTFOCUS: {
					if (event->active.gain) onInputFocus();
					else onInputBlur();
					break;
				}

				case SDL_APPACTIVE:    {
					if (event->active.gain) onRestore();
					else onMinimize();
					break;
				}
			}
			break;
		}

		case SDL_KEYDOWN: {
			onKeyDown(event->key.keysym.sym, event->key.keysym.mod, event->key.keysym.unicode);
            break;
        }

        case SDL_KEYUP: {
            onKeyUp(event->key.keysym.sym, event->key.keysym.mod, event->key.keysym.unicode);
            break;
        }

        case SDL_MOUSEMOTION: {
            onMouseMove(event->motion.x, event->motion.y, event->motion.xrel, event->motion.yrel,
            			(event->motion.state&SDL_BUTTON(SDL_BUTTON_LEFT))!=0, (event->motion.state&SDL_BUTTON(SDL_BUTTON_RIGHT))!=0,
            			(event->motion.state&SDL_BUTTON(SDL_BUTTON_MIDDLE))!=0);
            break;
        }

        case SDL_MOUSEBUTTONDOWN: {
            switch(event->button.button) {

            	case SDL_BUTTON_LEFT: {
                    onLButtonDown(event->button.x, event->button.y);
                    break;
                }

                case SDL_BUTTON_RIGHT: {
                    onRButtonDown(event->button.x, event->button.y);
                    break;
                }

                case SDL_BUTTON_MIDDLE: {
                    onMButtonDown(event->button.x, event->button.y);
                    break;
                }
            }
            break;
        }

        case SDL_MOUSEBUTTONUP:    {
            switch(event->button.button) {

                case SDL_BUTTON_LEFT: {
                    onLButtonUp(event->button.x, event->button.y);
                    break;
                }

                case SDL_BUTTON_RIGHT: {
                    onRButtonUp(event->button.x, event->button.y);
                    break;
                }

                case SDL_BUTTON_MIDDLE: {
                    onMButtonUp(event->button.x, event->button.y);
                    break;
                }
            }
            break;
        }

        case SDL_JOYAXISMOTION: {
            onJoyAxis(event->jaxis.which, event->jaxis.axis, event->jaxis.value);
            break;
        }

        case SDL_JOYBALLMOTION: {
            onJoyBall(event->jball.which, event->jball.ball, event->jball.xrel, event->jball.yrel);
            break;
        }

        case SDL_JOYHATMOTION: {
            onJoyHat(event->jhat.which, event->jhat.hat, event->jhat.value);
            break;
        }

        case SDL_JOYBUTTONDOWN: {
            onJoyButtonDown(event->jbutton.which, event->jbutton.button);
            break;
        }

        case SDL_JOYBUTTONUP: {
            onJoyButtonUp(event->jbutton.which, event->jbutton.button);
            break;
        }

        case SDL_QUIT: {
            onExit();
            break;
        }

        case SDL_SYSWMEVENT: {
            //Ignore
            break;
        }

        case SDL_VIDEORESIZE: {
        	onResize(event->resize.w, event->resize.h);
            break;
        }

        case SDL_VIDEOEXPOSE: {
            onExpose();
            break;
        }

        default: {
            onUser(event->user.type, event->user.code, event->user.data1, event->user.data2);
            break;
        }
    }
}

void events::onInputFocus() {
}

void events::onInputBlur() {
}

void events::onKeyDown(SDLKey sym, SDLMod mod, Uint16 unicode) {
}

void events::onKeyUp(SDLKey sym, SDLMod mod, Uint16 unicode) {
}

void events::onMouseFocus() {
}

void events::onMouseBlur() {
}

void events::onMouseMove(short mX, short mY, short relX, short relY, bool left, bool right, bool middle) {
}

void events::onMouseWheel(bool up, bool down) {
}

void events::onLButtonDown(short mX, short mY) {
}

void events::onLButtonUp(short mX, short mY) {
}

void events::onRButtonDown(short mX, short mY) {
}

void events::onRButtonUp(short mX, short mY) {
}

void events::onMButtonDown(short mX, short mY) {
}

void events::onMButtonUp(short mX, short mY) {
}

void events::onJoyAxis(Uint8 which, Uint8 axis, Sint16 value) {
}

void events::onJoyButtonDown(Uint8 which, Uint8 button) {
}

void events::onJoyButtonUp(Uint8 which, Uint8 button) {
}

void events::onJoyHat(Uint8 which, Uint8 hat, Uint8 value) {
}

void events::onJoyBall(Uint8 which, Uint8 ball, Sint16 xrel, Sint16 yrel) {
}

void events::onMinimize() {
}

void events::onRestore() {
}

void events::onResize(short w, short h) {
}

void events::onExpose() {
}

void events::onExit() {
}

void events::onUser(Uint8 type, int code, void* data1, void* data2) {
}


